package com.ibm.cloud.banking.customer.service;

import com.ibm.cloud.banking.annotation.PBS;
import com.ibm.cloud.banking.facade.account.dto.AccountInfoDTO;
import com.ibm.cloud.banking.facade.customer.ICustomerCommandFacade;
import com.ibm.cloud.banking.facade.customer.dto.CustomerAccountRelDTO;
import com.ibm.cloud.banking.platform.context.service.RequestContextHandler;
import com.ibm.cloud.invoker.PbsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

@PBS(servNo = "PBS200001")
@Slf4j
public class SavingCustAcctRelService implements PbsService<CustomerAccountRelDTO, Integer> {

    @Autowired
    ICustomerCommandFacade customerCommandFacade;

    private final static String COMPENSATE_PARAMS_KEY = "saving-cust-acct-rel-param-key";

    @Override
    public Integer doService(CustomerAccountRelDTO customerAccountRelDTO) {
        RequestContextHandler.putCompensate(COMPENSATE_PARAMS_KEY,customerAccountRelDTO);
        return customerCommandFacade.savingCustAcctRel(customerAccountRelDTO);
    }

    @Override
    public void compensate(CustomerAccountRelDTO data) {
        data = (CustomerAccountRelDTO)RequestContextHandler.getCompensate(COMPENSATE_PARAMS_KEY);
        customerCommandFacade.deleteCustAcctRel(data);
    }
}
